import http from "./http"
import ut from "@/assets/utils"
import store from "@/store"

// 获取系统定义类别
const querySysType =async ()=>{
	let cache = ut.storage.get('cache_sys_type')
	if(cache) return cache
	let arr = []
	try{
	 let {code,data}=await http.get('system/dict/data/type/iot_yes_no')
	 if(+code===200){
			arr = data.map(item=>{
				return {
					dictLabel:item.dictLabel,
					dictSort:item.dictSort
				}
			})
			ut.storage.set('cache_sys_type',arr)
	 }
	 
	}catch(_){}
	return arr
}

// 获取产品分类列表【支持分页/名字查询】
const queryCateData = obj =>{
	let { pageNum=1,pageSize=20,categoryName } = obj,
			params = {pageNum,pageSize}
	if(categoryName)params.categoryName = categoryName
	return http.get('iot/category/list',{params})
}

// 获取指定产品类别的详细信息
const queryCategoryInfo = (categoryId)=> http.get(`/iot/category/${categoryId}`)


// 新增产品分类信息 
const _categoryParams = {
	categoryName:'',
	orderNum:'',
	remark:'',
	categoryId:null,
	createBy:null,
	createTime: null,
	delFlag: null,
	isSys: null,
	parentId: null,
	tenantId: null,
	tenantName: null,
	updateBy: null,
	updateTime: null,
}
// 新增产品分类 
const insertCateData = obj =>{
	obj = Object.assign({},_categoryParams,obj)
	obj.createBy = store.state.profile?.user?.userName
	return http.post('/iot/category',obj)
}

export default{
	querySysType,
	queryCateData,
	queryCategoryInfo,
	insertCateData
}

